# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: leon

from coin.exchange.base.kr_rest.product import NativeProduct
from coin.exchange.gopax.kr_rest.constants import currency_list
from coin.exchange.gopax.kr_rest.currency import GopaxCurrency


class GopaxProduct(NativeProduct):
  _exchange = "Gopax"
  NativeCurrencyType = GopaxCurrency
  _quote = GopaxCurrency.FromStr('KRW')

  def __init__(self, base, quote):
    native_currency = base.native_currency
    assert native_currency in currency_list, native_currency
    assert quote.currency == 'KRW', quote
    native_symbol = '%s-%s' % (base.native_currency, quote.currency)
    super().__init__(base, self._quote, native_symbol)

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    pair = product.split('-')
    if len(pair) == 1:
      assert isinstance(product, str), type(product)
      base = GopaxCurrency.FromStrNativeCurrency(product)
      return cls(base, cls._quote)
    elif len(pair) == 2:
      base = GopaxCurrency.FromStrNativeCurrency(pair[0])
      quote = GopaxCurrency.FromStrNativeCurrency(pair[1])
      return cls(base, quote)
    else:
      raise ValueError(product)
